<script>
	var _this;
	import refreshToken from './utils/refreshToken.js';
	import toWeixin from './utils/toWeixin.js';
	/** @description 模块化js（必要） */
	import huoniaoTools from './utils/public/huoniaoTools.js';
	import pageToolsFunc from './utils/public/pageToolsFunc.js';
	import pageRequestFunc from './utils/public/pageRequestFunc.js';
	// 引入语句 ./vue.js script标签中
	var watchData = {}; //监听用
	let debugUrl = 'https://ihuoniao.cn'; // https://ihuoniao.cn;http://zjl.215000.com;ruyuedaojia.com 本地线上地址切换这个
	let run = false; //开发/运行设置成true,项目上线之后设置成false
	export default {
		async onLaunch(options) {
			_this = this;
			// 域名切换
			let platForm = uni.getSystemInfoSync().uniPlatform;
			//平台切换
			switch (platForm) {
				case 'web': { //H5
					_this.globalData.wxprivate = false;
					_this.globalData.appFullWh = window.appBoolean && (window.Android || location
						.href.includes('appFullScreen')) ? uni.upx2px(88) : 0; //app全屏状态栏高度
					_this.globalData.appFullScreen = window.appBoolean && window.Android ? 'appFullScreen=1' : '';
					_this.globalData.appBack = _this.globalData.appFullWh || !window.appBoolean; //后退按钮是否隐藏，在app中
					_this.globalData.appBoolean = window.appBoolean; //是否处于app
					_this.globalData.channelDomain = window.channelDomain; //app跳转使用
					let device = navigator.userAgent.toLowerCase();
					// 判断是否在微信浏览器内
					if (device.match(/MicroMessenger/i) == "micromessenger") { //处于微信环境中
						jWeixin.miniProgram.getEnv((res) => { //异步，函数调用不用监听，页面一加载就需要监听
							if (res.miniprogram) { //小程序
								_this.globalData.webMini = true;
								_this.globalData.webWeixin = false; //使之变化，从而被监听到
							} else { //微信浏览器
								_this.globalData.webWeixin = true;
								_this.globalData.webMini = false; //使之变化，从而被监听到
							}
						})
						
						
						
						
						
						
						
						
						
						
						
					} else {
						_this.globalData.webWeixin = false;
						_this.globalData.webMini = false;
					}
					// 判断是否在抖音浏览器
					if (device.includes("toutiaomicroapp")) {
						_this.globalData.webdyMini = true;
						// touTiao.miniProgram.getEnv(function(res) {
						// 	_this.globalData.webdyMini = Boolean(res.miniprogram);
						// });
					} else {
						_this.globalData.webdyMini = false;
					}
					this.globalData.advName = '移动端';
					this.globalData.masterDomain = (window.masterDomains || debugUrl); // https://ihuoniao.cn;http://zjl.215000.com
					uni.getStorage({
						key: 'cityInfo',
						success: res => {
							_this.globalData.cityInfo = res.data;
						},
						fail: res => {
							_this.getLocation('wgs84');
						}
					})
					if (window.loginUserId) {
						_this.globalData.userid = window.loginUserId;
						_this.memberInfo(window.loginUserId);
					}
					window.setupWebViewJavascriptBridge(function(bridge) {
						bridge.callHandler("setDragRefresh", {
							"value": 'off'
						}, function() {})
					})

					break;
				}
				case 'mp-toutiao': { //抖音
					_this.globalData.wxprivate = false;
					this.globalData.platform_name = 'platform_name=dy_miniprogram'; //用于encodeUrl
					this.globalData.advName = '抖音小程序'; //广告模板名称
					_this.globalData.webdyMini = true;
					_this.globalData.webWeixin = false;
					_this.globalData.webMini = false;
					this.globalData.masterDomain = (uni.getExtConfigSync && uni.getExtConfigSync()['extConfig']
						['masterDomain'] ? uni.getExtConfigSync()['extConfig']['masterDomain'] :
						debugUrl); // https://ihuoniao.cn;http://zjl.215000.com
					_this.getoutiaoConfig(); //抖音配置
					_this.getloSetting();
					const updateManager = uni.getUpdateManager();
					if (updateManager) {
						updateManager.onCheckForUpdate(function(res) {
							// 请求完新版本信息的回调
							console.log('是否有新版本: ', +res.hasUpdate)
							if (!res.hasUpdate) {
								uni.hideLoading()
							}
						})
						updateManager.onUpdateReady(function() {
							uni.hideLoading()
							uni.showModal({
								title: '更新提示',
								content: '新版本已经准备好，是否重启应用？',
								showCancel: false,
								success: function(res) {
									if (res.confirm) {
										// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
										updateManager.applyUpdate()
									}
								}
							})
						})
						updateManager.onUpdateFailed(function() {
							uni.hideLoading();
							uni.showModal({
								title: '提示',
								content: '检查到有新版本，但下载失败，请检查网络后重试',
								showCancel: false
							})
						})
					}
					uni.getStorage({
						key: 'userid',
						success: res => {
							_this.globalData.userid = res.data;
							_this.memberInfo(res.data);
						},
					})
					// 登录状态判断的定时器
					setInterval(res => {
						let userid = uni.getStorageSync('userid') || this.globalData.userid;
						let token = uni.getStorageSync('access_token');
						if (!userid || !token) {
							uni.removeStorage({
								key: 'userid'
							});
							uni.removeStorage({
								key: 'access_token'
							});
							uni.removeStorage({
								key: 'refresh_token'
							});
							uni.removeStorage({
								key: 'token_expired'
							});
							this.globalData.userid = null;
							this.globalData.access_token = null;
							this.globalData.refresh_token = null;
							this.globalData.token_expired = null;
						}
					}, 5000);
					let info = uni.getMenuButtonBoundingClientRect();
					uni.getSystemInfo({
						success: (res) => {
							_this.globalData.wh = res.windowHeight; //敞口大小
						},
						fail(err) {
							console.log(err);
						}
					});
					break;
				}
				case 'mp-weixin': { //微信
					
					/**
					 * 首先获取城市分站信息
					 * 适配单模块
					 */
					let cityId = uni.getExtConfigSync && uni.getExtConfigSync()['cityid'] ?
					uni.getExtConfigSync()['cityid'] : '';
					let cityName = uni.getExtConfigSync && uni.getExtConfigSync()['cityname'] ?
					uni.getExtConfigSync()['cityname'] : '';
					if(cityId && cityName){ //获取一下默认分站
						let cityInfo = {
							cityid: cityId,
							name: cityName
						}
						uni.setStorageSync('cityInfo', cityInfo);
						_this.globalData.cityInfo = cityInfo
					}
					this.init_weixin();
					// 避免重复执行onShow
					setTimeout(() => {
						_this.globalData.checkLogin = true; //冷启动 => 转换成热启动
					}, 1000);
					break;
				}
				default:{
					uni.showModal({
						title: '提示',
						content: '数据加载失败，请刷新小程序',
						success: function (res) {
							if (res.confirm) {
								uni.reLaunch({
									url: '/pages/index/index'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
								uni.reLaunch({
									url: '/pages/index/index'
								})
							}
						}
					});
				}
			}
			uni.getSystemInfo({
				success: res => {
					_this.globalData.phoneInfo = res;
				}
			});
			let cityDetail = uni.getStorageSync('cityInfo');
			if (cityDetail && typeof cityDetail == "string") {
				uni.removeStorageSync('cityInfo');
				uni.setStorageSync('cityInfo', JSON.parse(cityDetail));
			}
			this.globalData.platForm = platForm;
			this.globalData.userError = this.globalData.masterDomain + '/static/images/noPhoto_100.jpg';
			this.globalData.imgError = this.globalData.masterDomain + '/static/images/404.jpg';
			uni.removeStorageSync('manualChange'); //清除
			// console.log('当前运行的平台是：', platForm, '使用的域名是：', this.globalData.masterDomain);
			
			await _this.getIndexConfig();
			await _this.essentialData();
			_this.$isResolve();

			setTimeout(() => {
				// 加载字体文件
				let fontBaseUrl = this.globalData.masterDomain + '/static/fonts/'
				uni.loadFontFace({
					family: 'DLRG',
					global:true,
					source: `url(${fontBaseUrl}DINMittelschriftStd.ttf)`,
					success() {
					}
				})
				uni.loadFontFace({
					family: 'coregtd6',
					global:true,
					source: `url("${fontBaseUrl}coregtd6.ttf")`,
					success() {
					}
				})
				uni.loadFontFace({
					family: 'Number',
					global:true,
					source: `url("${fontBaseUrl}coregtd6.ttf")`,
					success() {
					}
				})
				uni.loadFontFace({
					family: 'Akrobat',
					global:true,
					source: `url("${fontBaseUrl}Akrobat-Black.ttf")`,
					success() {
					}
				})
				// uni.loadFontFace({
				// 	family: 'iconfont',
				// 	global:true,
				// 	source: `url("${fontBaseUrl}fonts-symbol/iconfont_1.ttf")`,
				// 	success() {
				// 		console.log('测试')
				// 	}
				// })
			}, 300);
		},
		onShow(options) {

			let fromShareVal = options.query.fromShare;
			if (fromShareVal) { //分享绑定
				if (this.globalData.userid) { //登录直接绑定关联账户
					this.bindShareFn(fromShareVal);
				} else { //未登录保存分享状态
					uni.setStorageSync('fromShare', fromShareVal);
				}
			}
			this.globalData.platForm = uni.getSystemInfoSync().uniPlatform;
			if (this.globalData.checkLogin) { //热启动需要验证
				// console.log('小程序后台没被杀 进入热启动')
				_this.initEndter(); //等待验证之后
			}
			if(this.globalData.appBoolean){
				if(!window.isCheckLogin){
					let login_user = window.$.cookie('HN_login_user') || window.$.cookie('HN_userid') || window.loginUserId
					let userid = window.$.cookie('HN_userid') || window.loginUserId
					if(login_user && userid != _this.globalData.userid){
						clearInterval(window.interval_checkLogin)
						window.loginUserId = userid
						this.globalData.userid = userid
						// this.reloadFn()
					}
				}else{
					if(window.loginCheckCount >= 3 && window.isCheckLogin){
						setTimeout(() => {
							if(!this.userid){
								location.href = this.globalData.masterDomain + '?appFullScreen=1&currentPageOpen=1'
							}
							window.isCheckLogin = false;
						}, 1500);
					}
				}

				setTimeout(() => {
					clearInterval(window.interval_checkLogin)
				}, 3000);
			}
		},
		onHide(){
			// if(this.globalData.appBoolean && window.interval_checkLogin && window.countLoginTime > 0 && window.countLoginTime < 3){ //设定成功
			// 	clearInterval(interval_checkLogin)
			// }
		},
		globalData: {
			// 信息参数
			userInfo: {}, //用户信息
			appFullWh: 0, //app全屏导航栏高度
			appFullScreen: '', //这里的值是appFullScreen=1或者''
			appBack: true, //app是否需要后退按钮
			webWeixin: -1, //H5页面是否处于微信浏览器，设置成-1是为了能监听到
			webMini: -1, //H5页面是否处于微信小程序中，设置成-1是为了能监听到
			webdyMini: -1, //H5页面是否处于抖音小程序中，设置成-1是为了能监听到
			appBoolean: false, //是否处于APP中
			channelDomain: '', //用于app跳转
			cityInfo: '', //分站信息
			userid: 0, //用户id
			lnglat: '', //当前经纬度信息(适用场景:退出模块即消失，重新进入重新定位)
			platForm: '', //运行的平台
			advName: '', //广告模板名称
			userError: '', //错误头像路径
			imgError: '', //错误图片路径(非头像)
			phoneInfo: '', //手机各项信息
			iOSMiniPay_forbid: false, //禁用ios支付
			iosMiniPay_msg: '', //禁用提示
			wxprivate: -1, //微信隐私是否需要弹出授权弹窗，不设置成true/false是为了让其他页面能够监听到这个值的变化
			wxprivateName: '', //微信隐私协议名称
			moduleAdv: {}, //模块广告数据
			// 配置参数
			appConfig: '', // app配置信息
			siteConfig: {}, //位置配置信息
			moduleConfig: {}, //模块配置信息，自己在模块内调用接口，保存到这里
			dyConfig: '', //抖音配置 
			imgVersion: (parseInt(new Date().valueOf() / 1000)), //图片版本号miniProgramTemplate: '',//设置为大首页的模块，
			accesskey_id: (uni.getExtConfigSync && uni.getExtConfigSync()['accesskey_id'] ? uni
				.getExtConfigSync()['accesskey_id'] : 'a96f536d906766f5'),
			// 地址参数
			imgStaticPath: (uni.getExtConfigSync && uni.getExtConfigSync()['masterDomain'] ? uni.getExtConfigSync()[
				'masterDomain'] : debugUrl) + '/static/images',
			imgPath: (uni.getExtConfigSync && uni.getExtConfigSync()['masterDomain'] ? uni.getExtConfigSync()[
				'masterDomain'] : debugUrl) + '/static/images/miniprograme', //小程序开发图片地址
			masterDomain: '', //请求数据的域名
			locationFn: function(fn = {}) { //定位方式
				let platForm = uni.getSystemInfoSync().uniPlatform;
				if (platForm == 'web') {
					window.HN_Location.init(function(value) {
						if (Boolean(value) && value != undefined) { //定位成功
							if (fn.success) {
								fn.success(value)
							}
						} else {
							console.log('定位失败')
							if (fn.fail) {
								fn.fail();
							}
						}
					}, !window.appBoolean);
				} else if (platForm == 'mp-weixin') {
					let positionType = _this.globalData.appConfig.cfg_miniProgramLocationAuth;
					if (!fn.fail) {
						fn = {
							...fn,
							...{
								fail: res => { //仅针对后台定位类型和线上不符的情况，其他情况暂不做处理
									let failStr =
										`fail the api need to be declared in the requiredPrivateInfos`;
									if (res.errMsg.includes(`getLocation:${failStr}`)) { //精确定位失效
										_this.globalData.appConfig.cfg_miniProgramLocationAuth =
											'chooseLocation';
										_this.globalData.locationFn(fn);
									} else if (res.errMsg.includes(`getFuzzyLocation:${failStr}`)) { //模糊定位失效
										_this.globalData.appConfig.cfg_miniProgramLocationAuth = 'getLocation';
										_this.globalData.locationFn(fn);
									}
								}
							}
						}
					}
					if (positionType == 'getLocation') { //精确定位
						uni.getLocation(fn);
					} else{ //模糊定位
						uni.getFuzzyLocation(fn);
					}

				} else {
					uni.getLocation(fn)
				}
			},
			// 微信平台专用参数
			navTop: 0, //微信小程序状态栏高度
			biasTop_88: 0, //88rpx高度的偏差（其他情况请调用app.biasTop）,在public_header.vue内被赋值
			loginMode: 0, //登录方式：0代表原生，1代表H5
			// 遗弃参数(从此行开始，下面所有参数均为遗弃参数，非遗弃参数不要往加到下面)
			// 未知参数(该参数也属于遗弃参数),严禁删除或者更改
			cityNum: '',
			ak: '',
			siteDebug: '',
			miniProgramName: '',
			defaultindex: '', //设置为大首页的模块，
			checkLogin: false, //静默登录   false => 表示冷启动   true => 表示热启动  热启动需要在onShow中
			// 仅在APP.VUE使用参数
		},
		methods: {
			...huoniaoTools,
			...pageToolsFunc,
			...pageRequestFunc,
			toWeixinFn(pageThis, callBackFn = {}) { //跳转的标签要加上minUrl="wxMiniprogram://原始id/appid"
				/*微信浏览器跳转小程序 (在)
					pageThis:页面的this
					callBackFn:{success:res=>{},fail:res=>{}}跳转成功/失败的回调
				*/
				_this.watchG('webWeixin', value => {
					if (value) {
						pageThis.$nextTick(res => {
							toWeixin(callBackFn);
						})
					}
				})
			},
			// 调用链：一般是线性的，因为其参数一般是父级的返回值，故通常情况下无法从中间调用。 
			async essentialData(callback) { //必要的数据,包括图片版本、appconFig数据等等
				let result = await _this.$ajax.get({ //图片版本
					url: 'data/admin/staticVersion.txt?v=' + ~(-new Date()),
					header: 'application/x-www-form-urlencoded;charset=UTF-8'
				});
				this.globalData.imgVersion = result.data;
				let res = await _this.$ajax.get({ //appConfig数据
					url: 'api/appConfig.json?v=' + ~(-new Date()),
					header: 'application/x-www-form-urlencoded;charset=UTF-8'
				});
				// 禁用微信支付
				if (res.data.cfg_iosVirtualPaymentState) { //开启禁用
					let systemInfo = uni.getSystemInfoSync();
					if (systemInfo.platform == 'ios' && (systemInfo.uniPlatform == 'mp-weixin'||_this.globalData.webMini)) {
						this.globalData.iOSMiniPay_forbid = true;
						this.globalData.iosMiniPay_msg = res.data.cfg_iosVirtualPaymentTip ? res.data
							.cfg_iosVirtualPaymentTip : '十分抱歉，由于相关规范，iOS小程序不支持该功能'; //提示
					}
				}
				let share_title = res.data.share.title
				res.data.share.title = share_title.split('$city').join(_this.globalData.cityInfo.name || '');
				res.data.share.description = res.data.share.description.split('$city').join( _this.globalData
					.cityInfo.name || '');
				this.globalData.appConfig = res.data;
				if (this.globalData.loginMode == 1) { //需要判断
					if (res.data.cfg_useWxMiniProgramLogin != 1) {
						this.globalData.loginMode = 1; //H5
					} else {
						this.globalData.loginMode = 0; //原生
					}
				}
				
				// 判断是否是单个城市分站
				if (res.data.site_city_count == 1) {
					// var cityInfo = uni.getStorageSync('cityInfo');
					if (res.data.site_city_info) { //如果本地没有存储cityInfo的信息 则使用默认城市分站
						var default_cityInfo = res.data.site_city_info;
						uni.setStorageSync('cityInfo', default_cityInfo);
						this.globalData.cityInfo = default_cityInfo
					}
				}
				
				if (callback) {
					callback(this.globalData)
				}
			},
			localSetting() { //缺少权限，引导用户如何操作，并返回操作结果
				uni.openSetting({
					success: function(res) {
						if (res.authSetting["scope.userLocation"] == true) {
							uni.showToast({
								title: '授权成功',
								icon: 'success',
								duration: 1000
							})
							_this.getLocation('wgs84');
						} else {
							uni.showModal({
								title: "需要您的授权",
								content: "授权后将会优先显示您附近的优惠信息",
								success(res) {
									if (res.confirm) {
										_this.localSetting();
									} else {
										_this.getdefaultCity(); //不授权定位则用默认的城市分站
									}
								},
								fail(err) {
									_this.getdefaultCity(); //不授权定位则用默认的城市分站
								},
							});
						}
					}
				})
			},
			getloSetting() { //1.获取用户当前的授权项
				uni.getSetting({
					success: (res) => {
						if (res.authSetting['scope.userLocation'] != undefined && res.authSetting[
								'scope.userLocation'] != true) {
							uni.authorize({ //2.请求指定项目授权
								scope: 'scope.userLocation',
								success: res => {
									uni.showToast({
										title: '授权成功',
										icon: 'success',
										duration: 1000
									})
									_this.getLocation('wgs84');
								},
								fail: err => {
									uni.showToast({
										title: '请授权地理位置信息',
										icon: 'none',
										duration: 1000
									})
									setTimeout(() => {
										_this.localSetting();
									}, 1000);
								}
							});

						} else if (res.authSetting['scope.userLocation'] == undefined) {
							//用户首次进入页面,调用wx.getLocation的API
							_this.getLocation('wgs84');
						} else {
							// console.log('授权成功')
							//调用wx.getLocation的API
							_this.getLocation('wgs84');
						}

					}
				});
				return false;
			},
			// 用户信息验证失败处理方式
			userInfoError(backUrl = '') { //backUrl：登录成功之后要跳转的地址，不传用后退
				//如果access_token不存在，直接清空storeage数据并跳转到登录页面
				if (!uni.getStorageSync('access_token')) {
					//退出
					uni.showToast({
						title: '账号状态异常，请重新登录！',
						icon: 'none',
						duration: 2000
					});
					uni.removeStorage({
						key: 'userid'
					});
					uni.removeStorage({
						key: 'access_token'
					});
					uni.removeStorage({
						key: 'refresh_token'
					});
					uni.removeStorage({
						key: 'token_expired'
					});
					_this.globalData.userid = null;
					_this.globalData.access_token = null;
					_this.globalData.refresh_token = null;
					_this.globalData.token_expired = null;
					if (backUrl) {
						_this.tologin(backUrl);
					} else if (!run) {
						_this.backFn('/pages/index', _this.globalData.masterDomain);
					}

					//如果access_token存在，并且接口还提示『用户信息验证失败』，可能是账号在多个设备上进行了登录，此时需要用refresh_token验证下状态，如果可用，则更新本地token，如果不可用，则清空storeage数据并回到首页
				} else {

					refreshToken.unit(uni.getStorageSync('refresh_token'),
						_this.globalData.masterDomain,
						function(datas) {
							if (datas.state == 100) {
								// console.log(datas.info);
								let access_token = datas.info.access_token;
								let refresh_token = datas.info.refresh_token;
								uni.setStorage({
									key: 'access_token',
									data: access_token
								});
								uni.setStorage({
									key: 'refresh_token',
									data: refresh_token
								});
								let token_expired = Date.parse(new Date()) / 1000 +
									7200 - 20; //两个小时有效期，保险起见，用1小时59分钟40秒
								uni.setStorage({
									key: 'token_expired',
									data: token_expired
								});
								_this.globalData.access_token = access_token;
								_this.globalData.refresh_token = refresh_token;
								_this.globalData.token_expired = token_expired;
							} else {
								//清除缓存数据
								uni.removeStorage({
									key: 'userid'
								});
								uni.removeStorage({
									key: 'access_token'
								});
								uni.removeStorage({
									key: 'refresh_token'
								});
								uni.removeStorage({
									key: 'token_expired'
								});
								_this.globalData.userid = null;
								_this.globalData.access_token = null;
								_this.globalData.refresh_token = null;
								_this.globalData.token_expired = null;
								let url = encodeURIComponent(`${_this.globalData
									.masterDomain}/logout.html?redirect=${_this.globalData.masterDomain}/login.html`);
								_this.linkTo(url, true);
							}
						}
					);
				}
			},
			// 定位方式（1）
			getLocation(type) { //小程序原生定位获取经纬度和省市(调用链1.1)
				var ulng = uni.getStorageSync("mylng");
				var ulat = uni.getStorageSync("mylat");
				if (ulng && ulat) {
					_this.getCity(ulat, ulng);
					return false;
				} else {
					uni.getLocation({
						type,
						success: function(res) {
							uni.setStorageSync('mylng', res.longitude);
							uni.setStorageSync('mylat', res.latitude);

							_this.getCity(res.latitude, res.longitude)
						},
						fail: function(res) {
							console.log(`getLocation调用失败`);

						},
						complete: function(res) {
							console.log('wancheng')
							console.log(res)
						}
					});
				}
			},
			getCity(slat, slng) { //根据经纬度获取城市信息(调用链1.2)
				_this.$ajax.get({
					url: 'include/ajax.php?service=siteConfig&action=getLocationByGeocoding&location=' + slat +
						',' + slng
				}).then(res => {
					let data = res.data,
						state = data.state;
					if (state == "100") {
						let list = data.info;
						let province = list.province;
						let city = list.city;
						let district = list.district;
						_this.getAddr(province, city, district)
					}
				})
			},
			getAddr(pro, city, distr) { //(调用链1.3)
				_this.$ajax.get({
					url: 'include/ajax.php?service=siteConfig&action=verifyCity&region=' + encodeURIComponent(
						pro) + '&city=' + encodeURIComponent(city) + '&district=' + encodeURIComponent(
						distr),
				}).then(res => {
					var data = res.data,
						state = data.state;
					if (state == "100") {
						uni.setStorageSync('cityInfo', data.info);
						uni.setStorageSync('cityname', data.info.name);
						uni.setStorageSync('cityid', data.info.cityid);
					} else {
						_this.getdefaultCity()
					}
				})
			},
			// 定位方式（2）
			getCityInfo(lng, lat, type, callback,callfail) { //接口定位获取城市相关信息（调用链1.1）
				var that = this;
				var dataPrarm = 'service=siteConfig&action=getLocationByGeocoding&coordtype=' + type + '&location=' +
					lat + ',' + lng;
				var urlData = that.encodeUrl(dataPrarm);
				_this.$ajax.post({
					url: 'include/ajax.php?' + urlData,
				}).then(res => {
					var data = res.data;
					if (data.state == 100) {
						var cityPosi = data.info;
						if (callback) {
							//回调
							callback(cityPosi);
							return;
						}
						if (that.globalData.appConfig && that.globalData.appConfig.site_city_auto_location) {
							that.getCurrCityInfo(cityPosi);
						}
					} else {
						if(callfail){
							callfail(data.info)
						}
						return false;
					}
				})
			},
			getCurrCityInfo(cityInfoArr, callback,noSkip = false) { //（调用链1.2）
				// noSkip => 新增参数 外卖手动选择定位 没有获取城市分站时禁止跳转
				var that = this;
				var dataPrarm =
					'service=siteConfig&action=verifyCity&region=' +
					cityInfoArr.province +
					'&city=' +
					cityInfoArr.city +
					'&town=' +
					cityInfoArr.town +
					'&district=' +
					cityInfoArr.district;
				var urlData = that.encodeUrl(dataPrarm);
				_this.$ajax.post({
					url: 'include/ajax.php?' + urlData,
				}).then(res => {
					var data = res.data;
					if (data.state == 100) {
						that.globalData.cityInfo = data.info;
						uni.setStorage({
							key: 'cityInfo',
							data: data.info
						});
					} else if(!noSkip){
						that.getdefaultCity();
					}
					if (callback) {
						//回调
						callback(data);
					}
				}).catch(res => {
					if(!noSkip){
						that.getdefaultCity();
					}
				})
			},
			// 定位给方式（3）
			chooseLoaction(fn, failFn) { // 选择定位
				uni.chooseLocation({
					success: (res) => {
						uni.hideLoading()
						fn(res);
					},
					fail: (res) => {
						uni.hideLoading()
						failFn();
					}
				});
			},
			accurateLoaction(fn, failFn) { //精确定位
				uni.getLocation({
					type: 'gcj02',
					success: res => {
						uni.hideLoading()
						fn(res)
					},
					fail: res => {
						uni.hideLoading()
						failFn();
					}
				});
			},
			getCurrLocation(callback) { // 模糊定位
				var that = this;
				uni.getFuzzyLocation({
					type: 'gcj02',
					success(res) {
						if (that.siteDebug) {
							uni.showModal({
								title: '获取定位_app.js',
								content: JSON.stringify(res.authSetting),
								success(res) {
									if (res.confirm) {
										console.log('用户点击确定');
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						}
						if (res.errMsg == 'getFuzzyLocation:ok') {
							//成功获取定位
							// const lng =  tt.change(res.latitude,res.longitude).lng;
							// const lat = tt.change(res.latitude,res.longitude).lat;
							// var lnglat = tt.change(res.latitude,res.longitude)
							var lnglat = res.longitude + ',' + res.latitude;
							uni.setStorage({
								key: 'currlocation',
								data: lnglat
							});
							callback(res);
						}
					},
					fail(res) {
						// 获取当前城市分站
						try {
							var value = uni.getStorageSync('cityInfo');
							if (value) {
								that.cityInfo = JSON.parse(value);
							} else {
								that.getdefaultCity();
							}
						} catch (e) {
							console.log('CatchClause', e);
							console.log('CatchClause', e);
							// Do something when catch error
							that.getdefaultCity();
						}
					}
				});
			},
			// globalData数据监听，使用:watch('监听目标',页面this,回调函数)
			//注意：1.监听的属性名要和页面中要设置的属性名对应上，如：监听userInfo,那页面要赋值的属性名也要是userInfo
			//     2.页面和组件只能监听一个属性，比如组件已经监听了appConfig,那在调用该组件的页面内就不能再监听appConfig了
			// watchG(key, __this, fn = function() {}) {
			// 	let data = this.globalData;
			// 	Object.defineProperty(data, key, { //增加/修改一个现有的值
			// 		configurable: true, //修改配置项开启
			// 		enumerable: true, //遍历开启
			// 		set: function(value) { //key被改变的时候执行
			// 			__this[key] = value;
			// 			fn(value);
			// 		},
			// 		get: function(value) {
			// 			return __this[key] //必要，否则监听模板的值会变成undefined
			// 		} //在其他页面调用key的时候执行
			// 	})
			// },
			watchG(key, fn = function() {}) { //监听globalData中首次变化（一般是接口返回）
				let blankArr = ['[]', '{}', '""', 'false', 'null', 'undefined', '-1']; //空状态的值
				let blankBool = blankArr.includes(JSON.stringify(_this.globalData[key])); //空状态
				if (!blankBool && !watchData[key]) { //未监听过，接口提前返回值
					fn(_this.globalData[key]);
					return false;
				}
				let newObj = { //重新整理数据
					func: fn,
					watch: true //监听标记
				};
				if (!watchData[key]) { //首次监听该数据 
					watchData[key] = [newObj];
					Object.defineProperty(_this.globalData, key, { //增加/修改一个现有的值
						configurable: true, //修改配置项开启
						enumerable: true, //遍历开启
						set: function(value) { //key被改变的时候执行
							if (watchData[key] instanceof Array) { //首次变化
								let length = watchData[key].length;
								for (let i = 0; i < length; i++) {
									watchData[key][i].func(value);
								}
								watchData[key] = value; //对象转成数组，且仅存储目标数据，减小存储空间消耗
							} else if (!watchData[key]) {
								watchData[key] = value
							}
						},
						get: function(value) {
							if (watchData[key] instanceof Array && watchData[key][0].watch) { //未触发监听,就获取
								return '';
							} else {
								return watchData[key]
							}
						} //在其他页面调用key的时候执行
					})
				} else if ((watchData[key] instanceof Array) && watchData[key][0].watch) { //前面已经设置了监听，但是值还未返回
					watchData[key].push(newObj);
				} else { //设置监听且已经有值了
					fn(watchData[key]);
				}
			},
			//获取手机号码并绑定给当前用户
			bindUserPhoneNumber: function(tt, data, callback) {
				var phoneData;
				var that = this;
				var dataset = data.currentTarget.dataset;
				if (!data.detail.encryptedData && !data.detail.iv) {
					uni.showToast({
						title: '已拒绝小程序授权',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				uni.login({
					success: (res) => {
						var code = res.code;
						uni.getUserInfo({
							success: function(res) {
								// console.log(res);
								uni.login({
									success: (res) => {
										phoneData = {
											code: res.code,
											encryptedData: data.detail
												.encryptedData,
											iv: data.detail.iv
										};
										// console.log(phoneData);
										var dataPrarm =
											'service=member&action=updateAccount&do=chphone&phoneData=' +
											JSON.stringify(phoneData);
										var urlData = that.encodeUrl(dataPrarm);
										_this.$ajax.post({
											url: 'include/ajax.php?' +
												urlData,
										}).then(res => {
											var data = res.data;
											if (data.state ==
												100) {
												//更新用户绑定手机状态
												tt.userPhoneCheck =
													1
												uni.showLoading({
													title: '获取中...'
												});
												if (callback) {
													//回调方法中判断了是否需要支付
													callback();
												} else {
													that.callPhone(
														tt, '',
														dataset
													);
												}
											} else {
												uni.showToast({
													title: data
														.info,
													icon: 'none',
													duration: 2000
												});
											}
										})
									}
								});
							},
							error: function(res) {
								console.log(res);
								return false;
							}
						});
					}
				});
			},
			rsaEncrypt(data) {
				var encryptPubkey = this.globalData.appConfig.cfg_encryptPubkey;
				if (typeof JSEncrypt == 'object') {
					var returnData = [];

					//验证公钥
					if (typeof encryptPubkey == 'undefined' || encryptPubkey == '') {
						return data;
					}
					data = data.toString();
					var pubkey = encryptPubkey;
					pubkey = pubkey.replace('-----BEGIN PUBLIC KEY-----\n', '');
					pubkey = pubkey.replace('\n-----END PUBLIC KEY-----', '');
					var encrypt = new JSEncrypt.JSEncrypt();
					encrypt.setPublicKey(pubkey);

					//内容长度大于100，自动分组
					if (data.length > 100) {
						var lt = data.match(/.{1,2}/g);
						lt.forEach(function(entry) {
							returnData.push(encrypt.encrypt(entry));
						});
					} else {
						returnData.push(encrypt.encrypt(data));
					}
					return returnData.join('||rsa||'); //多个分组数据用||rsa||分隔，后台接收时需要先进行分组解密再组合
				} else {
					return data;
				}
			},
			/**
			 * 无感登录  测试版
			 * 
			 * 
			 * 
			 * 无感登录 步骤
			 * 1.获取token  没有获取到 => 2登录   获取到 => 3验证token
			 * 2.无感登录
			 * 3.验证token是否过期   过期 =>  清除token              未过期 => 不需要操作   
			 * 
			 * 版本2
			 * 1. 获取token  有token 说明已经登录  需验证 是否过期/失效
			 * 2.静默登录 
			 * 3.过期需要刷新token
			 * 
			 * 
			 * 问题是如何获取知道 token失效
			 * 如果token失效 最多5秒可以请求通知接口
			 * **/
			// 初始化
			async init_weixin(platForm) {
				_this.globalData.wxprivate = false;
				this.globalData.webdyMini = false;
				this.globalData.loginMode = 1; //是否需要根据后台设置调整登录方式,需要的话就设置1，抖音同理
				this.globalData.advName = '小程序'; //广告模板名称
				this.globalData.masterDomain = (uni.getExtConfigSync && uni.getExtConfigSync()['masterDomain'] ?
					uni.getExtConfigSync()['masterDomain'] : debugUrl
				); // https://ihuoniao.cn;http://zjl.215000.com
				const updateManager = uni.getUpdateManager();
				if (updateManager) {
					updateManager.onCheckForUpdate(function(res) {
						// 请求完新版本信息的回调
						console.log('是否有新版本: ', +res.hasUpdate)
					})
					updateManager.onUpdateReady(function() {
						uni.showModal({
							title: '更新提示',
							content: '新版本已经准备好，是否重启应用？',
							showCancel: false,
							success: function(res) {
								if (res.confirm) {
									// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
									updateManager.applyUpdate()
								}
							}
						})
					})
					updateManager.onUpdateFailed(function() {
						uni.showModal({
							title: '提示',
							content: '检查到有新版本，但下载失败，请检查网络后重试',
							showCancel: false
						})
					})
				}
				let info = uni.getMenuButtonBoundingClientRect();

				uni.getSystemInfo({
					success: (res) => {
						_this.globalData.navTop = res.safeArea.top ? res.safeArea.top : res
							.statusBarHeight;
						_this.globalData.navHeight = res.statusBarHeight + info.height + (info.top -
							res
							.statusBarHeight) * 2;
						_this.globalData.navRight = res.screenWidth - info.left + 24;
						_this.globalData.ww = res.windowWidth; //敞口大小
						_this.globalData.wh = res.windowHeight; //敞口大小
					},
					fail(err) {
						console.log(err);
					}
				});

				_this.globalData.userid = uni.getStorageSync('userid');
				console.log('launch执行')
				await _this.initEndter(); //等待验证之后


				if (_this.globalData.userid) { // 此处修改原因:memberInfo方法调用需要有用户id  没有不需要调用
					_this.memberInfo(_this.globalData.userid);
				}
				uni.getStorage({
					key: 'cityInfo',
					success: res => {
						_this.globalData.cityInfo = res.data;
					},
					fail: res => {
						_this.getLocation('wgs84');
					}
				})






			},

			async initEndter() {
				const that = this;
				let token = uni.getStorageSync('access_token');
				let userid = uni.getStorageSync('userid') || this.globalData.userid;
				if (token && userid) { //如果token并且用户id存在  则验证token是否过期
					console.log('获取到token/userid需要验证')
					await that.checkToken();
				} else {
					let logoutSelf = uni.getStorageSync('logoutSelf');
					console.log('获取是否自己退出登录过')
					if (!logoutSelf) {
						console.log('未自行退出  需要登录')
						await that.getCode(); //首先获取code
					}

				}
			},

			// 验证token是否过期   direct => 直接刷新token
			checkToken(direct) {
				const that = this;
				let token_expired = uni.getStorageSync('token_expired');
				let old_refresh_token = uni.getStorageSync('refresh_token'); //刷新token
				let nowtime = Date.parse(new Date()) / 1000;
				let userid = uni.getStorageSync('userid') || this.globalData.userid;
				let token = uni.getStorageSync('access_token');
				if (nowtime >= token_expired || direct) {
					uni.removeStorageSync('access_token');
					uni.removeStorageSync('refresh_token');
					uni.removeStorageSync('token_expired');
					that.globalData.access_token = null;
					that.globalData.refresh_token = null;
					that.globalData.token_expired = null;
					return new Promise(resolve => {
						refreshToken.unit(old_refresh_token, that.globalData.masterDomain, function(data) {
							
							if (data.state == 100) { //更新成功
								var access_token = data.info.access_token;
								var refresh_token = data.info.refresh_token;
								uni.setStorageSync("access_token", access_token);
								uni.setStorageSync("refresh_token", refresh_token);
								//两个小时有效期，保险起见，用1小时59分钟40秒
								let token_expired = Date.parse(new Date()) / 1000 + 7200 - 20;
								// console.log('5分钟过期')
								uni.setStorageSync("token_expired", token_expired)
								that.globalData.access_token = access_token;
								that.globalData.refresh_token = refresh_token;
								that.globalData.token_expired = token_expired;
								// console.log('已更新token')
							} else { //数据有问题  重新登录
								console.log('运行到此处，说明token已失效,需要重新登录')
								if (nowtime >= token_expired) {
									//如果token还在有效期内  =>  其他设备登录   暂定不继续登录 
									// 如果token快要过期  需要登录
									that.getCode()
								}
							}
						})
					})
				} else {
					if (!userid || !token) {
						// console.log('checkToken没有获取到用户信息  重新登录')
						that.getCode()
						return false;
					}
					let interval = setInterval(res => {
						let userid = uni.getStorageSync('userid') || this.globalData.userid;
						let token = uni.getStorageSync('access_token');
						if (!userid || !token) {
							uni.removeStorage({
								key: 'userid'
							});
							uni.removeStorage({
								key: 'access_token'
							});
							uni.removeStorage({
								key: 'refresh_token'
							});
							uni.removeStorage({
								key: 'token_expired'
							});
							this.globalData.userid = null;
							this.globalData.access_token = null;
							this.globalData.refresh_token = null;
							this.globalData.token_expired = null;
							clearInterval(interval)
							that.getCode();
						}
						// console.log('当前登录状态判定结果：', !userid || !token ? '未登录' : '已登录');
					}, 5000);
				}
			},

			// 获取code ，登录
			getCode() {
				const that = this;
				// console.log('请求登录')
				let codeGet = new Promise(resolve => {
					uni.login({
						success: function(res) {
							that.code = res.code;
							resolve(res);
						}
					})
				})
				codeGet.then(res => {
					// console.log('执行request',res)
					that.request(); //登录请求
				})

			},

			// 登录接口
			request() {
				const that = this;
				_this.$ajax.post({
					url: `include/ajax.php?service=member&action=miniProgramLogin&code=${that.code}`,
				}).then(res => {
					if (res.data) {
						let data = res.data;
						if (data.state == 100) {
							let userid = '';
							let access_token = '';
							let refresh_token = '';
							let urlParam = data.info.split('?')[1];
							userid = that.getUrlPara(urlParam, 'uid');
							access_token = that.getUrlPara(urlParam, 'access_token');
							refresh_token = that.getUrlPara(urlParam, 'refresh_token');
							uni.setStorageSync("userid", userid)
							uni.setStorageSync("access_token", access_token)
							uni.setStorageSync("refresh_token", refresh_token)
							let token_expired = Date.parse(new Date()) / 1000 + 7200 -
								20; //两个小时有效期，保险起见，用1小时59分钟40秒
							uni.setStorageSync("token_expired", token_expired)
							// console.log('5fenzhong过期')
							that.globalData.userid = userid;
							that.globalData.access_token = access_token;
							that.globalData.refresh_token = refresh_token;
							that.globalData.token_expired = token_expired;
							// console.log('登录成功')
							if (that.globalData.checkLogin) { //冷启动不需要加载会员信息 
								// console.log('热启动用户信息获取')
								that.memberInfo(userid); //用户信息获取
							}

						} else {
							_this.userData = {}; //重置
							_this.canIUse = true; //重置
						}
					} else {
						_this.userData = {}; //重置
						_this.canIUse = true; //重置
					}
				}).catch(res => {
					_this.userData = {}; //重置
					_this.canIUse = true; //重置
				})
			},

			// 导航原生页面判断
			urlProcess(code, url) { //一个是原生页面code，一个是h5链接
				let platForm = this.globalData.platForm;
				let config = this.globalData.appConfig;
				let arrModule = [];
				if (platForm == 'mp-weixin') {
					arrModule = config.wxmini_native_module;
				} else if (platForm == 'mp-toutiao') {
					arrModule = config.dymini_native_module;
				}
				let bool = Array.isArray(arrModule) && arrModule.includes(code);
				if (bool) {
					return {
						type: 'mini',
						value: code
					} //使用原生
				} else {
					return {
						type: 'web',
						value: url
					} //使用h5
				}
			},

			/**
			 * diy页面 url跳转
			 * @param {object} obj 跳转链接 相关信息 
			 * @param {Number} redirect   是否redirectTo  1 => 是
			 * @param {Boolean} isALink  是否像a链接一样跳转
			 * */
			diyLinkTo(obj, redirect = 0,isALink = false) {
				const that = this;
				if (obj && obj.linkInfo) {
					if(obj.linkInfo.linkText && obj.link.includes('/29/')){
						obj.link = obj.link.replace('/29/',`/${that.globalData.userid}/`)
					}
					if (that.globalData.platForm == 'mp-weixin' || that.globalData.platForm == 'mp-toutiao') {
						if (obj.linkInfo && obj.linkInfo.linkText == '切换个人版') {
							if(that.globalData.appConfig.cfg_userCenterDiy == 1 && !obj.linkInfo.moduleCode){
								obj.link = '/pages/member/index/index'
								redirect = 1
							}else if(obj.linkInfo.moduleCode){
								redirect = 1
								obj.mini = ''
								obj.linkInfo.mini = ''
							}
						} else if (obj.linkInfo && obj.linkInfo.linkText == '切换商家版' ) {
							if(that.globalData.appConfig .cfg_busiCenterDiy == 1){
								obj.link = '/pages/packages/company/index/index'
								redirect = 1
							}else{
								redirect = 1
								obj.mini = ''
								obj.linkInfo.mini = ''
							}
						}

					}else if(that.globalData.platForm == 'web' && obj.linkInfo && obj.linkInfo.linkText == '切换个人版'){
						location.href = obj.link;
						return false;
					}
					let url = obj.link ? obj.link : '';
					if (url.includes('tel:')) {
						obj.linkInfo.type = 4
					}
					let mini_path = obj.linkInfo && obj.linkInfo.mini || ''
					if(obj.linkInfo.homePage){  
						//此处表明是主页  自定义页面link已做id连接处理 直接跳转link即可
						mini_path = obj.link; 
					}

					switch (obj.linkInfo.type) {
						case 1: //普通链接
							if (url) {
								if (that.globalData.platForm == 'web' && that.globalData.appBoolean) {
									if(!window.Android && (url.indexOf('work.weixin.qq.com') > -1 || url.includes('tel:'))){
										location.href = url.indexOf('work.weixin.qq.com') > -1 ? ('tel:' + _this.globalData.siteConfig.hotline) : url
										return false;
									}
									if (url.includes('wxMiniprogram://')) {
										var ahref = url.replace('wxMiniprogram://', '');
										var miniId = ahref.split('?/')[0];
										var //小程序原始id
											path = ahref.split('?/')[1]; //跳转的路径
										var _ghId = miniId.split('/')[0];
										var _appid = miniId.split('/')[1];
										var _path = path ? '/' + path : '';

										window.setupWebViewJavascriptBridge(function(bridge) {
											if (path && path.indexOf('huoniao/') > -1) {
												bridge.callHandler('redirectToWxMiniProgram', {
													'id': _ghId,
													'path': path.replace('huoniao/',
														'/pages/redirect/index?url=/')
												}, function(responseData) {});
											} else {
												bridge.callHandler('redirectToWxMiniProgram', {
													'id': _ghId,
													'path': path
												}, function(responseData) {});
											}

										});

										return false;
									}
									let paramStr = url.indexOf('?') > -1 ? url.split('?')[1] : ''
									let paramArr = paramStr.split('&');
									let newParamArr = []
									for (let i = 0; i < paramArr.length; i++) {
										let param = paramArr[i].split('=')[0];
										let val = paramArr[i].split('=').length > 1 ? paramArr[i].split('=')[1] : '';
										if (/.*[\u4e00-\u9fa5]+.*$/.test(val)) {
											newParamArr.push(param + '=' + encodeURIComponent(val))
										} else {
											newParamArr.push(param + '=' + val)
										}
									}
									if (obj.linkInfo && obj.linkInfo.name) {
										newParamArr.push('addPage=' + obj.linkInfo.name)
									}
									let newParamStr = newParamArr.join('&')
									let newUrl = url.split('?')[0] + '?' + newParamStr;
									if(isALink && !window.Android){
										location.href = newUrl
									}else{
										let path_parmaObj = {}
										if(obj.linkInfo.mini && obj.linkInfo.miniPath_code){
											let mod = obj.linkInfo.miniPath_code;
											let path_mini = obj.linkInfo.mini.split('?')[0]
											let temp = path_mini.split('/')[path_mini.split('/').length - 1]
											let path_paramStr = obj.linkInfo.mini.split('?').length > 1 ? obj.linkInfo.mini.split('?')[1] : ''
											
											if(path_paramStr){
												let path_paramArr = paramStr.split('&');
												for( let i = 0; i < path_paramArr.length; i++){
													let path_str = path_paramArr[i]
													let path_key = path_str.split('=')[0]
													let path_val = path_str.split('=').length > 1 ? path_str[1] : ''
													path_parmaObj[path_key] = path_val
												}
												path_parmaObj['url'] = newUrl
												path_parmaObj['module'] = mod
												path_parmaObj['template'] = temp
											}
										}
										if(!window.Android){
											path_parmaObj = {
												'name': '',
												'code': obj.linkInfo && obj.linkInfo.name ? obj.linkInfo.name :
													'', //原生模块 跳原生页面
												'link': (newUrl)
											}
										}
										window.setupWebViewJavascriptBridge(function(bridge) {
											bridge.callHandler((window.Android ? 'redirectTo':'redirectNative'), path_parmaObj, function(res) {												
											});
										})
									}
								} else if (that.globalData.platForm == 'web') {
									if (url.indexOf('http') > -1 || url.indexOf('/pages/') != 0) {
										url = url.indexOf('http') > -1 ? url : 'https://' + url;
										// console.log('测试22')
										location.href = url;
									} else {
										uni[redirect ? 'redirectTo' : 'navigateTo']({
											url: obj.link
										});
									}
								} else {
									if (url.indexOf('work.weixin.qq.com/kfid') > -1) {
										//小程序跳转客服
										var link = url.split('?id=')[0];
										var //客服链接
											id = url.split('?id=')[1]; //企业ID
										var path = '/pages/openkf/openkf?url=' + encodeURIComponent(link) + '&id=' + id;
										if (link && id) {
											uni.openCustomerServiceChat({
												extInfo: {
													url: link
												},
												corpId: id,
												success(res) {
													// console.log(res);
												}
											});
										} else {
											uni[redirect ? 'redirectTo' : 'navigateTo']({
												url: '/pages/redirect/index?url=' + encodeURIComponent(that
													.addUrlParam(
														url))
											});
										}
									} else if (url.includes('wxMiniprogram://')) {
										var ahref = url.replace('wxMiniprogram://', '');
										var miniId = ahref.split('?/')[0];
										var //小程序原始id
											path = ahref.split('?/')[1]; //跳转的路径
										var _ghId = miniId.split('/')[0];
										var _appid = miniId.split('/')[1];
										var _path = path ? '/' + path : '';
										uni.navigateToMiniProgram({
											appId: _appid,
											path: _path,
											success(res) {
												// wx.navigateBack();
											},
											fail(res) {
												uni.showToast({
													title: res,
													icon: 'success',
													duration: 2000
												});
											}
										});

									}else if(mini_path){
										uni[redirect ? 'redirectTo' : 'navigateTo']({
											url: mini_path
										});
									}else if (url.includes('tomini')) {
										let arr = url.split('?')[1].split('&');
										for (let i = 0; i < arr.length; i++) {
											if (arr[i].includes('tomini')) {
												url = arr[i].replace('tomini=', '');
												arr.splice(i, 1);
												break;
											}
										}
										url += `?${arr.join('&')}`;
										uni[redirect ? 'redirectTo' : 'navigateTo']({
											url: url
										});
									} else if (url.indexOf('http') > -1 || (url.indexOf('/pages/') != 0 && url.includes(
											'/pages/') && !url.includes('wxMiniprogram://'))) {
										if (obj.linkInfo && obj.linkInfo.name) { //新增  目的是判断当前模块是否有原生页面
											let newUrl = that.urlProcess(obj.linkInfo.name, url);
											if (newUrl.type == 'mini') { //有原生页面
												url = `/pages/packages/${obj.linkInfo.name}/index/index`; //模块首页
												uni[redirect ? 'redirectTo' : 'navigateTo']({
													url: url
												});
											} else { //没有原生页面 
												uni[redirect ? 'redirectTo' : 'navigateTo']({
													url: '/pages/redirect/index?url=' + encodeURIComponent(that
														.addUrlParam(url))
												});
											}
										}else { //普通链接
											
											url = url.indexOf('http') > -1 ? url : 'https://' + url
											uni[redirect ? 'redirectTo' : 'navigateTo']({
												url: '/pages/redirect/index?url=' + encodeURIComponent(that
													.addUrlParam(url))
											});
										}
									} else {
										uni[redirect ? 'redirectTo' : 'navigateTo']({
											url: obj.link
										});
									}

								}
							}
							break;
						case 2: // 扫一扫
							// 允许从相机和相册扫码
							if (that.globalData.platForm != 'web') {

								uni.scanCode({
									success: function(res) {
										// console.log('条码类型：' + res.scanType);
										// console.log('条码内容：' + res.result);

										if (res.result.indexOf('http') > -1) {
											let url = res.result.indexOf('http') > -1 ? res.result :
												'https://' + res.result
											uni[redirect ? 'redirectTo' : 'navigateTo']({
												url: '/pages/redirect/index?url=' + encodeURIComponent(
													that.addUrlParam(url))
											});
										} else if (res.result.indexOf('EAN_13,') > -1) {
											var resultStr = res.result.split('EAN_13,');
											let url = that.globalData.masterDomain +
												'/include/ajax.php?service=shop&action=barcodeSearch&type=redirect&code=' +
												resultStr[1];
											uni[redirect ? 'redirectTo' : 'navigateTo']({
												url: '/pages/redirect/index?url=' + encodeURIComponent(
													that.addUrlParam(url))
											});
										} else if (res.result.indexOf('/pages/') > -1) {
											uni[redirect ? 'redirectTo' : 'navigateTo']({
												url: res.result
											});
										} else {
											uni.showModal({
												title: '扫码结果',
												content: res.result,
												showCancel: false,
												success: function(res) {
													if (res.confirm) {
														console.log('用户点击确定');
													}
												}
											});
										}
									},
									error: function(res) {
										console.log('扫码失败' + res)
									}
								});
							} else {
								if (that.globalData.appBoolean) {
									window.setupWebViewJavascriptBridge(function(bridge) {
										bridge.callHandler("QRCodeScan", {}, function callback(DataInfo) {
											if (DataInfo) {
												// APP端已做处理，不需要前端跳转
												// if(DataInfo.indexOf('http') > -1){
												// 	location.href = DataInfo;
												// }else{
												// 	alert(DataInfo);
												// }
											}
										});
									})
								} else if (that.globalData.webWeixin) { //微信浏览器
									window.jWeixin.scanQRCode({
										// 默认为0，扫描结果由微信处理，1则直接返回扫描结果
										needResult: 1,
										desc: '扫一扫',
										success: function(res) {
											if (res.resultStr) {
												if (res.resultStr.indexOf('http') > -1) {
													location.href = res.resultStr;
												} else if (res.resultStr.indexOf('EAN_13,') > -1) {
													var resultStr = res.resultStr.split('EAN_13,');
													location.href =
														'/include/ajax.php?service=shop&action=barcodeSearch&type=redirect&code=' +
														resultStr[1];
												} else {
													alert(res.resultStr);
												}
											}
										},
										fail: function(err) {
											alert(JSON.stringify(err));
										}
									});
								}
							}
							break;
						case 3: //下拉菜单
							// that.dropMenuShow = true;
							console.log('下拉菜单')
							break;
						case 4: //电话
							if (that.globalData.appBoolean && that.globalData.platForm == 'web') {
								window.location.href = 'tel:' + (obj.link.replace('tel:', ''))
							} else {
								uni.makePhoneCall({
									phoneNumber: obj.link.replace('tel:', '') //仅为示例
								});
							}
							break;
					}
				} else if (obj && typeof(obj) == 'string' || obj.link) {
					let url = typeof(obj) == 'string' ? obj : obj.link;
					if(!url) return false; //表明是空连接
					if (that.globalData.platForm == 'web' && that.globalData.appBoolean) {
						let paramStr = url.indexOf('?') > -1 ? url.split('?')[1] : ''
						let paramArr = paramStr.split('&');
						let newParamArr = []
						for (let i = 0; i < paramArr.length; i++) {
							let param = paramArr[i].split('=')[0];
							let val = paramArr[i].split('=').length > 1 ? paramArr[i].split('=')[1] : '';
							if (/.*[\u4e00-\u9fa5]+.*$/.test(val)) {
								newParamArr.push(param + '=' + encodeURIComponent(val))
							} else {
								newParamArr.push(param + '=' + val)
							}
						}
						let newParamStr = newParamArr.join('&')
						let newUrl = url.split('?')[0] + '?' + newParamStr; //将链接中的中文encode一下
						if(isALink && !window.Android){
							location.href = newUrl
						}else{
							window.setupWebViewJavascriptBridge(function(bridge) {
								bridge.callHandler('redirectNative', {
									'name': '',
									'code': '',
									'link': (newUrl)
								}, function() {
	
								});
							})
						}
					} else if (that.globalData.platForm == 'web') {
						if (url.indexOf('http') > -1 || url.indexOf('/pages/') != 0) {
							url = url.indexOf('http') > -1 ? url : 'https://' + url
							location.href = url;
						} else {
							uni[redirect ? 'redirectTo' : 'navigateTo']({
								url: url
							});
						}
					} else {
						if (url.includes('tomini')) {
							let arr = url.split('?')[1].split('&');
							for (let i = 0; i < arr.length; i++) {
								if (arr[i].includes('tomini')) {
									url = arr[i].replace('tomini=', '');
									arr.splice(i, 1);
									break;
								}
							}
							url += `?${arr.join('&')}`;
						}
						if (url.indexOf('http') > -1 || url.indexOf('/pages/') != 0) {
							url = url.indexOf('http') > -1 ? url : 'https://' + url
							uni[redirect ? 'redirectTo' : 'navigateTo']({
								url: '/pages/redirect/index?url=' + encodeURIComponent(that.addUrlParam(url))
							});
						} else {

							uni[redirect ? 'redirectTo' : 'navigateTo']({
								url: url
							});
						}

					}
				}
			},
		}
	}
</script>
<style>
	@import url('/static/fonts-symbol/iconfont.css');
	body,page{
		font-family: "PingFang SC","Hiragino Sans GB","STHeiti","Microsoft YaHei","Microsoft JhengHei","Source Han Sans SC","Noto Sans CJK SC","Source Han Sans CN","Noto Sans SC","Source Han Sans TC","Noto Sans CJK TC","WenQuanYi Micro Hei",SimSun,sans-serif
	}
	.fn-clear:after {
		visibility: hidden;
		display: block;
		font-size: 0;
		content: " ";
		clear: both;
		height: 0;
	}

	.fn-left {
		float: left;
	}

	.fn-right {
		float: right;
	}

	.fn-hide {
		display: none !important;
	}

	.loadingImg {
		background: linear-gradient(to right, #f6f7f8 0%, #edeef1 10%, #f6f7f8 20%, #f6f7f8 100%);
		background-size: 200% 100%;
		animation: flow 2s linear infinite;
	}

	.appBlank {
		/* app详情页用，保证内容加载*/
		position: absolute;
		bottom: 0;
		right: 0;
		height: 1px;
	}

	.advLabel {
		/* 广告标识标签 (只用给父级加一个relative即可)*/
		position: absolute;
		width: 48rpx;
		height: 28rpx;
	}

	.advLabel._0_ {
		top: 10rpx;
		left: 10rpx;
	}

	.advLabel._1_ {
		top: 10rpx;
		right: 10rpx;
	}

	.advLabel._2_ {
		bottom: 10rpx;
		left: 10rpx;
	}

	.advLabel._3_ {
		bottom: 10rpx;
		right: 10rpx;
	}

	.perfectScroll {
		/*滚动内容和下拉刷新冲突处理*/
		-webkit-user-drag: none;
		user-select: none;
		overscroll-behavior: none;
		-webkit-touch-callout: none;
		-webkit-user-select: none;
		-khtml-user-select: none;
	}

	body{
		font-family: "PingFang SC","Hiragino Sans GB","STHeiti","Microsoft YaHei","Microsoft JhengHei","Source Han Sans SC","Noto Sans CJK SC","Source Han Sans CN","Noto Sans SC","Source Han Sans TC","Noto Sans CJK TC","WenQuanYi Micro Hei",SimSun,sans-serif
	}

	/* 主要适配鸿蒙折叠手机 */
	@media (min-width:620px) {
		body{
			zoom: .579;
		}
	}
	@keyframes flow {
		0% {
			background-position: 50% 0;
		}

		100% {
			background-position: -150% 0;
		}
	}

	/* @font-face {
		font-family: "DLRG";
		src: url("/pages/packages/static/fonts/DINMittelschriftStd/DINMittelschriftStd.ttf"),
			url("/pages/packages/static/fonts/DINMittelschriftStd/DINMittelschriftStd.eot"),
			url("/pages/packages/static/fonts/DINMittelschriftStd/DINMittelschriftStd.otf");
	}

	@font-face {
		font-family: "coregtd6";
		src: url('/pages/packages/static/fonts/coregtd6/coregtd6.otf'),
			url('/pages/packages/static/fonts/coregtd6/coregtd6.ttf'),
			url('/pages/packages/static/fonts/coregtd6/coregtd6.woff');
	}

	@font-face {
		font-family: "Akrobat";
		src: url("/pages/packages/static/fonts/Akrobat-Black/Akrobat-Black.woff2"),
			url("/pages/packages/static/fonts/Akrobat-Black/Akrobat-Black.woff"),
			url("/pages/packages/static/fonts/Akrobat-Black/Akrobat-Black.ttf"),
			url("/pages/packages/static/fonts/Akrobat-Black/Akrobat-Black.eot"),
			url("/pages/packages/static/fonts/Akrobat-Black/Akrobat-Black.otf");
	} */
</style>